package com.kalvin.kvf.modules.ks.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.ks.entity.KSIntentionCust;
import com.kalvin.kvf.modules.ks.service.KSIntentionCustService;

import java.util.List;


/**
 * <p>
 * 抖音客户表 前端控制器
 * </p>
 * @since 2023-11-13 16:52:58
 */
@RestController
@RequestMapping("ks/intentionCust")
public class KSIntentionCustController extends BaseController {

    @Autowired
    private KSIntentionCustService intentionCustService;

    @RequiresPermissions("ks:intentionCust:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("ks/intentionCust");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("ks/intentionCust_edit");
        KSIntentionCust intentionCust;
        if (id == null) {
            intentionCust = new KSIntentionCust();
        } else {
            intentionCust = intentionCustService.getById(id);
        }
        mv.addObject("editInfo", intentionCust);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(KSIntentionCust intentionCust) {
        Page<KSIntentionCust> page = intentionCustService.listIntentionCustPage(intentionCust);
        return R.ok(page);
    }

    @RequiresPermissions("ks:intentionCust:add")
    @PostMapping(value = "add")
    public R add(KSIntentionCust intentionCust) {
        intentionCustService.save(intentionCust);
        return R.ok();
    }

    @RequiresPermissions("ks:intentionCust:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List<Long> ids) {
        intentionCustService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("ks:intentionCust:edit")
    @PostMapping(value = "edit")
    public R edit(KSIntentionCust intentionCust) {
        intentionCustService.updateById(intentionCust);
        return R.ok();
    }

    @RequiresPermissions("ks:intentionCust:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        intentionCustService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(intentionCustService.getById(id));
    }

    /**
     * 设置为未联系
     * @param ids
     * @return
     */
    @RequiresPermissions("ks:intentionCust:edit")
    @PostMapping(value = "editnoStatus")
    public R editnoStatus(@RequestParam("ids") List<Long> ids) {
        intentionCustService.editnoStatus(ids);
        return R.ok();
    }

    /**
     * 设置为已联系
     * @param ids
     * @return
     */
    @RequiresPermissions("ks:intentionCust:edit")
    @PostMapping(value = "editStatus")
    public R editStatus(@RequestParam("ids") List<Long> ids) {
        intentionCustService.editStatus(ids);
        return R.ok();
    }

}

